from flask_script import Manager
from flask_migrate import Migrate, MigrateCommand
from info import create_app, db
from flask import current_app
import logging

"""
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
import redis
from flask_wtf.csrf import CSRFProtect
from flask_session import Session
from config import config_dict
"""

# # 创建项目配置类
# class Config(object):
#     # 开启debug模式
#     DEBUG = True
# #     数据库链接配置
#     SQLALCHEMY_DATABASE_URI = "mysql://root:mysql@127.0.0.1:3306/re_information"
#     SQLALCHEMY_TRACK_MODIFICATIONS = False
# #     redis配置
#     REDIS_HOST = "127.0.0.1"
#     REDIS_PORT = 6379
#     REDIS_NUM = 6
#     """工程配置信息"""
#     SECRET_KEY = "EjpNVSNQTyGi1VvWECj9TvC/+kq3oujee2kTfQUs8yCM6xX9Yjq52v54g+HVoknA"
#     # flask_session的配置信息
#     SESSION_TYPE = "redis"  # 指定 session 保存到 redis 中
#     SESSION_USE_SIGNER = True  # 让 cookie 中的 session_id 被加密签名处理
#     SESSION_REDIS = redis.StrictRedis(host=REDIS_HOST, port=REDIS_PORT)  # 使用 redis 的实例
#     PERMANENT_SESSION_LIFETIME = 86400  # session 的有效期，单位是秒
"""----"""
# # 1.创建app对象
# app = Flask(__name__)
# # 注册配置信息到app对象
# app.config.from_object(config_dict["development"])
# # 创建数据库对象
# db = SQLAlchemy(app)
# # 创建redis数据库对象
# redis_store = redis.StrictRedis(host=config_dict["development"].REDIS_HOST, port=config_dict["development"].REDIS_PORT, db=config_dict["development"].REDIS_NUM)
# # 开启CSRF后端保护机制
# csrf = CSRFProtect(app)
# """工程配置信息"""
# Session(app)

app = create_app("development")
"""Manager管理数据库"""
manager = Manager(app)
# 初始化迁移对象
Migrate(app, db)
# 将迁移命令添加到管理对象中
manager.add_command('db', MigrateCommand)


# @app.route('/')
# def index():
#     return 'index  WTF'

if __name__ == '__main__':

    """日志一般在视图函数中,不在此处定义"""
    # logging.debug("This is a debug log.")
    # logging.info("This is a info log.")
    # logging.warning("This is a warning log.")
    # logging.error("This is a error log.")
    # logging.critical("This is a critical log.")

    # current_app.logger.info("使用flask封住info日志信息")

    manager.run()
